/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		   */
/*																   */
/*	NAME	  = t__sqlserver_bigint_add.c						   */
/*	NOTE	  = 												   */
/*	DATE	  = 2016/04/07 by songbb							   */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <sybase/config.h>
#include <sybase/sybase_core.h>
#include <sybase/sybase_common.h>
#include <sybase/sybase_token.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,
                 (char *) "\x00\x1a\x00\x00\x00\x00\x04\x34\x34\x34\x34\x01\x00\x00\x00\x20\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00",
                 28);
    L7session_sybase *p_st_session = (L7session_sybase *) frmalloc(sizeof(L7session_sybase));
    memset(p_st_session, 0x0, sizeof(L7session_sybase));
    p_st_session->i_lint2_endian = BYTE_BIG_ENDIAN;
    p_st_session->i_lint4_endian = BYTE_BIG_ENDIAN;
    long l_cursor_id = 0;
    char arr_cursor_name[30] = {0};


    i_ret = sybase_parse_curinfo3_token(p_st_data, FR_YES, p_st_session, &l_cursor_id, arr_cursor_name);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_STRING_EQUAL(arr_cursor_name, "\x34\x34\x34\x34");
    sybase_destroy_session(&p_st_session);
    bytebuff_free(&p_st_data);
    return;
}


static void __case2(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,
                 (char *) "\x00\x10\x00\x00\x00\x00\x04\x34\x34\x34\x34\x01\x00\x00\x00\x20\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00",
                 28);
    L7session_sybase *p_st_session = (L7session_sybase *) frmalloc(sizeof(L7session_sybase));
    memset(p_st_session, 0x0, sizeof(L7session_sybase));
    p_st_session->i_lint2_endian = BYTE_BIG_ENDIAN;
    p_st_session->i_lint4_endian = BYTE_BIG_ENDIAN;
    long l_cursor_id = 0;
    char arr_cursor_name[30] = {0};


    i_ret = sybase_parse_curinfo3_token(p_st_data, FR_YES, p_st_session, &l_cursor_id, arr_cursor_name);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);
    sybase_destroy_session(&p_st_session);
    bytebuff_free(&p_st_data);
    return;
}


static void __case3(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,
                 (char *) "\x00\x1a\x00\x00\x00\x00\x10\x34\x34\x34\x34\x01\x00\x00\x00\x20\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00",
                 28);
    L7session_sybase *p_st_session = (L7session_sybase *) frmalloc(sizeof(L7session_sybase));
    memset(p_st_session, 0x0, sizeof(L7session_sybase));
    p_st_session->i_lint2_endian = BYTE_BIG_ENDIAN;
    p_st_session->i_lint4_endian = BYTE_BIG_ENDIAN;
    long l_cursor_id = 0;
    char arr_cursor_name[30] = {0};


    i_ret = sybase_parse_curinfo3_token(p_st_data, FR_YES, p_st_session, &l_cursor_id, arr_cursor_name);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);
    sybase_destroy_session(&p_st_session);
    bytebuff_free(&p_st_data);
    return;
}


static void __case4(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,
                 (char *) "\x00\x1a\x00\x00\x00\x00\x04\x34\x34\x34\x34\x05\x00\x00\x00\x20\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00",
                 28);
    L7session_sybase *p_st_session = (L7session_sybase *) frmalloc(sizeof(L7session_sybase));
    memset(p_st_session, 0x0, sizeof(L7session_sybase));
    p_st_session->i_lint2_endian = BYTE_BIG_ENDIAN;
    p_st_session->i_lint4_endian = BYTE_BIG_ENDIAN;
    long l_cursor_id = 0;
    char arr_cursor_name[30] = {0};


    i_ret = sybase_parse_curinfo3_token(p_st_data, FR_YES, p_st_session, &l_cursor_id, arr_cursor_name);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);
    sybase_destroy_session(&p_st_session);
    bytebuff_free(&p_st_data);
    return;
}


static void __case5(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,
                 (char *) "\x00\x1a\x00\x00\x00\x00\x04\x34\x34\x34\x34\x01\x00\x00\x00\x40\x00\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00",
                 28);
    L7session_sybase *p_st_session = (L7session_sybase *) frmalloc(sizeof(L7session_sybase));
    memset(p_st_session, 0x0, sizeof(L7session_sybase));
    p_st_session->i_lint2_endian = BYTE_BIG_ENDIAN;
    p_st_session->i_lint4_endian = BYTE_BIG_ENDIAN;
    long l_cursor_id = 0;
    char arr_cursor_name[30] = {0};

    i_ret = sybase_parse_curinfo3_token(p_st_data, FR_YES, p_st_session, &l_cursor_id, arr_cursor_name);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);
    sybase_destroy_session(&p_st_session);
    bytebuff_free(&p_st_data);
    return;
}

static void __case6(void)
{
    int i_ret = FR_SUCC;
    Frbyte_Packet *p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data,
                 (char *) "\x00\x1a\x00\x00\x00\x00\x04\x34\x34\x34\x34\x01\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00",
                 24);
    L7session_sybase *p_st_session = (L7session_sybase *) frmalloc(sizeof(L7session_sybase));
    memset(p_st_session, 0x0, sizeof(L7session_sybase));
    p_st_session->i_lint2_endian = BYTE_BIG_ENDIAN;
    p_st_session->i_lint4_endian = BYTE_BIG_ENDIAN;
    long l_cursor_id = 0;
    char arr_cursor_name[30] = {0};


    i_ret = sybase_parse_curinfo3_token(p_st_data, FR_NO, p_st_session, &l_cursor_id, arr_cursor_name);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    sybase_destroy_session(&p_st_session);
    bytebuff_free(&p_st_data);
    return;
}

int add_suite_sybase_parse_curinfo3_token(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" sybase_parse_curinfo3_token()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL ||
        CU_add_test(pSuite, "case6", __case6) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
